package com.muyan.common.utils;

import java.util.Random;

/**
 * 随机工具类
 *
 * @author zzl 2018/03/19
 */
public class RandUtil {

    public static final String SEED_LOWER = "abcdefghijklmnopqrstuvwxyz";
    public static final String SEED_UPPER = SEED_LOWER.toUpperCase();
    public static final String SEED_NUM = "0123456789";
    public static final String SEED_SYMBOL = "+/=&$@#!";
    public static final String SEED_FULL = SEED_LOWER + SEED_UPPER + SEED_NUM;

    /**
     * 大小写字母随机
     */
    public static String randStr(int len) {
        return randStr(SEED_LOWER + SEED_UPPER, len);
    }

    /**
     * 数字随机
     */
    public static String randNumStr(int len) {
        return randStr(SEED_NUM, len);
    }

    /**
     * 小写字母+数字随机
     */
    public static String randLonStr(int len) {
        return randStr(SEED_LOWER + SEED_NUM, len);
    }

    /**
     * 大小写字母+数字随机
     */
    public static String randLnStr(int len) {
        return randStr(SEED_FULL, len);
    }

    /**
     * 给定种子随机
     */
    public static String randStr(String seed, int len) {
        if (seed == null || len <= 0) {
            return "";
        }
        int sendLen = seed.length();
        Random random = new Random();
        StringBuilder builder = new StringBuilder();

        for (int i = 0; i < len; i++) {
            builder.append(seed.charAt(random.nextInt(sendLen)));
        }
        return builder.toString();
    }


}
